home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amnesia 7
/
Amnesia - Issue 07 (1991-11-23)(Eclipse).adf
/
text
/
print_text
< prev
next >
Wrap
Text File
|
1989-05-09
|
14KB
|
330 lines
Hi there, Gazzer/Eclipse here with a very simple Program that will just print
some text on the current CLI screen, No more, no less. So, if you are after some
more advanced source code then please look elsewhere, or at least you could
write to me and just ask, and I'll be happy to oblige, my address can be found
at the end of this article, however if you are new to Assembly Language coding
on the Amiga Please Read on...
I'll give the whole program first and then follow on afterwards with a simple
but detailed discussion of what each part of the program does.
Incidentally, I'm not expecting you to write all of this program down on paper
and then Type the whole lot into Devpac, but if you have the time... you never
know you might learn something while you're typing it in! So, this file can
be found in the text\print_text file on this disk. Just cut out the program
between these Labels: 'Program Starts Here....' and 'Program Ends Now...'.
--------------------------------- Program Starts Here.... ---------------------
; A Simple Routine to Print text to the Current CLI Screen.
; I've used the Dos WRITE routine.
; by Gazzer/Eclipse
; Use Devpac 2 to compile.
; Please Assemble to Disk and then run from the CLI, otherwise DEVPAC
; will open a newcli and print the text, then close it immediately, without
; you getting a chance to view the Output. Thanks. Gazzer.
Opt C- ; Turn off Case Sensitivity
Openlib = -408 ; Offset for Exec Openlib Function
Closelib = -414 ; Offset " " Closelib Function
ExecBase = 4 ; Exec Library Base Address
Output = -60 ; Function to Retrieve current CLI handle/ID
Write = -48 ; Dos Library Write Function Offset
Start:
Move.l ExecBase,a6 ; Pointer to ExecBase Address
Lea dosname,a1 ; Name of Library
Moveq #0,d0 ; Any Version
Jsr Openlib(a6) ; Open Dos Library
Move.l d0,dosbase ; Store Dos Library Base Address
beq error ; If d0 = 0 didn't work so Goto error label
Move.l dosbase,a6 ; Move Dos Library Base Address into A6
Jsr Output(a6) ; Find current CLI
Move.l d0,handle ; And, find the it's handle
Move.l handle,d1 ; CLI handle
Move.l #text,d2 ; Text Address
Move.l #textend-text,d3 ; Text Length
Jsr Write(a6) ; Output Text
Move.l ExecBase,a6 ; Exec Structure Address
Move.l dosbase,a1 ; Dos Library Base
Jsr Closelib(a6) ; Close Dos Library
error: Moveq #0,d0 ; Don't care about Version
rts ; Return to the CLI
Text: dc.b $0C ; Clears Screen, I Put This in for Clarity
dc.b "This message should get printed out! Signed: Gazzer",$0a
dc.b "And now for the second line of the text.",$0a
dc.b "Might as well put a third one in too!!!",$0a
dc.b $0A ; Linefeed, put this in for tidiness
dc.b 0 ; It's advisable to Use '0' to terminate string
TextEnd
even
Handle: dc.l 0
dosbase dc.l 0
dosname dc.b "dos.library",0
end
------------------------------- Program Ends Now.... ---------------------------
First Things First
==================
8 Bits = 1 Byte
16 Bits = 2 Bytes = 1 Word
32 Bits = 4 Bytes = 2 Words = 1 LongWord
$ signifies a Hex Value
% signifies a Binary Value
No prefix signifies a Decimal value.
Registers are like little 'boxes' where you can store values up to
32 Bits, which is a Longword. So, we use Bytes, Words and Longwords when we are
coding, these have different extensions:
.b = Byte Value
.w = Word Value
.l = LongWord Value
The Registers which you will hear about are Address Registers, Data Registers
and the Amiga-Specific Custom Registers. Let's Look at these....
Data Registers:
---------------
Data Registers hold data, what a surprise!! There are 8 registers: D0 to D7
They are used as 'scratch' areas to hold values or addresses etc.
Address Registers:
------------------
Address Registers go from A0 to A7 (with A7 being reserved for the System.)
These are used to store certain Address of program Variables or Labels.
Let's continue with a brief introduction to the Motorola 68000 Instruction set:
The MOVE instruction
--------------------
Probably the most commonly used instruction, it does what it says.
And the form is Move <Source> <Destination> with notable examples
being:
Note: Move defaults to a word move i.e. Move.w
Move #4,d0 which would an immediate value i.e. '4' to Data
Register D0.
Move value,d0 which moves the value contained at the label 'value'
into the Data Register D0.
Move.l #value,d0 which would move the address of the label 'value' into
the Data register D0.
Moveq #0,d0 which would move a small value, anything up to and
including 0 to 127 . This is faster than the standard
Move, and as such should be used whenever possible and
relevant.
Move.w #4,a0 Same as Move #4,d0 except moveing into an address
Register.
Move.w #6,(a0) Note the brackets! This moves the value '6' into
the address location of whatever A0 points to.
i.e. say we have a label (not another one!) as such:
label: dc.w 0
If i did Move.w #66,(a0) this would move '66' into the Variable,
so the value of it would now be 66, i.e.
Label: dc.w 66
Might as well discuss labels and variable...
Say we had a label as below:
Label: dc.b 6
This would mean that the Label or variable 'Label' contains a value of 6 in Byte
Format, i.e two bytes, so the binary value would be: 00000110
And if we had a another variable like so
Another: dc.b 99
This value '99' would be expressed in Binary as follows: 01100011
In fact the Byte range would be from 0 to 255 decimal.
And a word value contained at a lable...
Wordvalue: dc.w 20000
The Maximum Value held in a word variable can be from 0 to 65535
The last one is the Longword which can be up to 2**32 (2 to the Power of 32)
in size.
The LEA instruction
-------------------
This stands for Load Effective Address. And what it does is get the address of
a given labeland place in in an Address Register only.
Lea Label,A0
Which moves the address of a variable called Label into Address Register A0.
The BSR instruction
-------------------
This stands for Branch to Sub-routine, rather like a GOSUB in Basic, or
Routine(); in C. The Syntax is BSR LABEL,
THE Bcc instructions
--------------------
The Bcc Branch Condition series consist of BEQ, BGT, BLS, BGE, BLE, BRA,
BNE, BLT etc. etc. BRA stands for Branch, which is a GOTO (Aaarrgghh)
i.e. it branches to the Label specified and continues on from there,
the syntax is BRA LABEL
The JSR instruction
-------------------
Similar to BSR, but used to Jump to a Sub-routine at a further distance
away in memory or in the Program. The syntax is JSR LABEL
The RTS instruction
-------------------
This Returns you from a BSR or RTS. It's like a RETURN at the end of a
GOSUB in Basic, or a '}' bracket signifying the end of a routine in C.
Other instructions are be Add, Sub, Divu, Mulu, etc., which would be Add,
Subtract, Divide, Multiply etc. But there are really too many of them to
mention. So, I won't.
Now Finally a discussion of the above program
=============================================
Firstly we have to stick an OPT C- , which is a Devpac only Operand and
what is does is not to differentiate between Lower and Uppercase letters.
Next, we have some Equates, i.e Openlib = -408, or you might see it as
Openlib equ -408, this just initializes some set variables which don't
change at all in the program.
Then there's the START: label, which can be anything at all, you don't even
need one, but I think it's nice to let people know where you're program starts.
Then we need to Open the Dos Library, which resides in memory. We do not
actually have the Address in memory, because it can reside anywhere in memory
and changes in different Kickstart Versions anyway. BUT, we do have the address
of the EXEC library which is also memory resident and always open and available.
So, Move the value stored in the EXECBASE equate, i.e 4, which comes out as
address 4 in memory, which is the Base Address of the Exec Library Structure in
to the A6 Address register.
Now, we are going to open the Dos Library Proper using the EXEC OpenLibrary
routine, and this needs two parametes, D0 must contain the version number of
the Library, i've set it to 0, coz it doesn't matter. Now we also need the
name of the Library that we want to open, and this is ALWAYS in lower case, and
in this case is 'dos.library' which is stored at the Dosname Label. So, we put
the address of Dosname in A1. Then we JSR to this Library function, which is
(please read this bit slowly while standing on one leg) an offset from the
base address, i.e the Library routines are stored Back in Memory. So, using the
JSR Openlib(a6) command, we are actually saying JSR -408(a6).
If we encounter an error, i.e. if the Routines returns a null value '0' in D0
then we were not successful in opening the Library and Go to the Erro Label
and Exit the Program and go back to the CLI. Otherwise we continue....
Now that we have the Dos Library Open, all is wonderful and we can continue
on wearing a smile and relax, if you've got this far in the text, I must
congratulate you on staying Awake and Sane!!
Noe, we must find out how to access the CLI Screen, we have run the Program
from. We Load the DosBase address into register A6. We then use a DOS Library
routine called Output(), which tells us what the current CLI 'handle' or ID is.
We don't need to supply any parameters. and if all goes well (which it will)
then we have the 'handle' in d0. Then we just save this value to a variable
called Handle, for later use.
Now to the action packed bit, we actually get to write something to the Screen!
We Use the DOS Write() routine, which needs some parameters, namely the CLI
handle in D1, the address of the Text to Print in D2, the size of the Text
that we want to print in D3. Then we Access offset -48 from the Dos Library
Base address stored in Dosbase. So, we have JSR -48(a6), which actually
prints the text on screen stored at the text label.
Now that we've accomplished what we want in the program we must do some tidying
up and then exit back to the CLI. We first of all Move the EXECBASE address
'4' into the A6 address Register. Next we need to supply the Dos Library Base
Address in A1, then we call the EXEC CloseLib() function to close the DOS
Library.
Now we exit gracefully be setting the Program Return Value stored in Register
D0 to 0, by doing a nice Moveq #0,d0. and then we RTS, i.e. Return from
Subroutine, which effectively ends the Program safely.
At the end of the Program, we have different Variables:
Text: dc.b $0C ; Clears Screen, I Put This in for Clarity
dc.b "This message should get printed out! Signed: Gazzer",$0a
dc.b "And now for the second line of the text.",$0a
dc.b "Might as well put a third one in too!!!"
dc.b $0A ; Linefeed, Just put this in for tidiness
dc.b $0A ; Linefeed, also put this in for tidiness
dc.b 0 ; It's advisable to Use '0' to terminate.
TextEnd
The first one is where we store the text we want to print on the screen.
I've put $0C, which is the Hex Value of 12, which is a Code for clearing the
screen. The Text is stored in Character of Byte format, hence the dc.b "
prefix. I have also put in the Linefeed code $0a, which is 10 decimal, which
just goes on to next line on the screen. You can of course leave out these
codes if you only want to print one line of text. I just put them in for
Neatness. Next we have the Label TextEnd which is used in the Program to
work out the end of the text, so when we say Text-TextEnd, we are actually
getting the Length of all of the text! Clever, Eh!!
Then 'even' operand just makes our current Address Even, coz the Amiga and
the 68000 Processor really hate odd addresses!
even
Handle: dc.l 0
dosbase dc.l 0
dosname dc.b "dos.library",0
Next, is were we store the CLI ID number or handle, and we use a longword
to store this as it comes in that form. The Same with the DosBase Address
Variable which is also a LongWord, so that we can store a 32 Bit address.
Next, is the name of the Dos Library, which needs to be in lower case.
Finally, we put the END operand at the end of the program, this is not
absolutely necessary, but is a good idea all the same.
Well, that's my lot for this month, hope someone finds this article useful
and if you have any comments/feedback then please feel free to Write to me
at the following address.
Gazzer/Eclipse
3, O' Curry Rd
Sth Cir Road
Dublin 8
Ireland
See ya, Gazzer.